package com.itfreer.power.dao.user;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.itfreer.form.api.JdbcBaseDaoImp;
import com.itfreer.power.entity.user.UserAuthenticationEntity;

/**
 * 定义用户认证信息持久化操作类
 */
@Transactional(readOnly = false)
@Component("jdbcUserAuthenticationDao")
public class JdbcUserAuthenticationDao extends JdbcBaseDaoImp<UserAuthenticationEntity, JdbcUserAuthenticationEntity> implements UserAuthenticationDao {
	
	@SuppressWarnings({ "deprecation"})
	@Override
	public UserAuthenticationEntity getEntityByAccounts(String accounts) {
		Session session = this.sessionFactory.getCurrentSession();
		Criteria crit = session.createCriteria(JdbcUserAuthenticationEntity.class);
		crit.add(Restrictions.eq("accounts", accounts));
		JdbcUserAuthenticationEntity jEntity = (JdbcUserAuthenticationEntity) crit.uniqueResult();
		if (jEntity == null) {
			return null;
		}
		return jEntity.toEntity();
	}
	
}
